//2864.最大二进制奇数
//https://leetcode.cn/problems/maximum-odd-binary-number/?envType=daily-question&envId=2024-03-13
class Solution {
public:
    string maximumOddBinaryNumber(string s) {
        int n = s.size();
        int cur = n - 1;
        if (s[n-1] == '0')
        {
            while (cur >= 0 && s[cur] == '0') --cur;
            if (s[cur] == '0') return s;
            swap(s[n-1], s[cur]);
        }

        cur = 0;
        for (int i = 0; i < n - 1; ++i)
        {
            cur = i;
            if (s[i] == '0') while (cur < n - 1 && s[cur] == '0') ++cur;
            if (cur < n - 1) swap(s[i], s[cur]);
        }
        return s;
    }
};